home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / DJSRC111.ZIP / go32 / ed / symify.c < prev    next >
C/C++ Source or Header  |  1993-11-30  |  1KB  |  63 lines

  1. #include <stdio.h>
  2. #include "ed.h"
  3. #include "syms.h"
  4.  
  5. #define SC(r,c) (*(char *)(sc + (r)*ScreenCols() + (c)))
  6. #define SW(r,c) (*(sc + (r)*ScreenCols() + (c)))
  7.  
  8. TSS a_tss;
  9. main(int argc, char **argv)
  10. {
  11.   int r, c;
  12.   short *sc;
  13.   char *n;
  14.   char buf[90];
  15.   int i, line;
  16.   word32 v;
  17.   word32 d;
  18.   char *func, *file;
  19.  
  20.   if (argc < 2)
  21.   {
  22.     fprintf(stderr, "Usage: symify <program>\n");
  23.     fprintf(stderr, "This program replaces the stack dumps from go32 with debug info\n");
  24.     return 1;
  25.   }
  26.   syms_init(argv[1]);
  27.  
  28.   sc = (short *)malloc(ScreenRows() * ScreenCols() * 2);
  29.  
  30.   ScreenRetrieve(sc);
  31.  
  32.   for (r=0; r<ScreenRows(); r++)
  33.   {
  34.     if (SC(r,0) == ' ' && SC(r,1) == ' ' && SC(r,2) == '0' && SC(r,3) == 'x')
  35.     {
  36.       buf[8] = 0;
  37.       for (i=0; i<8; i++)
  38.         buf[i] = SC(r, i+4);
  39.       sscanf(buf, "%x", &v);
  40.       func = syms_val2name(v, &d);
  41.       file = syms_val2line(v, &line, 0);
  42.       buf[0] = 0;
  43.       if (func)
  44.       {
  45.     strcpy(buf, func);
  46.     if (d)
  47.       sprintf(buf+strlen(buf), "%+d", d);
  48.       }
  49.       if (file)
  50.       {
  51.         if (buf[0])
  52.           strcat(buf, ", ");
  53.         sprintf(buf+strlen(buf), "line %d of %s", line, file);
  54.       }
  55.       if (buf[0])
  56.         for (i=0; buf[i]; i++)
  57.           SW(r, 15+i) = 0x0f00 + buf[i];
  58.     }
  59.   }
  60.  
  61.   ScreenUpdate(sc);
  62. }
  63.